﻿#region
/*******************************************************************************
** File Name:		    AdminUserRightService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Phoenix.Service.Contracts;
using Phoenix.Service.Model;
using Phoenix.IBatisRepository;
using Phoenix.Respository;
using System.Data;
using Phoenix.Entity;

namespace Phoenix.Service
{
    public class AdminUserRightService : IAdminUserRightService 
    {
		 IAdminUserRight adminUserRight = new AdminUserRightRepository();
		 
		 #region  Auto Generation
		 
        public void AddAdminUserRight(AdminUserRightModel model)
        {
			EAdminUserRight entity = ConvertModelToEntity(model);
			
            adminUserRight.AddAdminUserRight(entity);
        }

		public void UpdateByAdminUserRightID (AdminUserRightModel model)
		{
			EAdminUserRight entity = ConvertModelToEntity(model);

            adminUserRight.UpdateByAdminUserRightID(entity);

		}

		public void DeleteByAdminUserRightID (System.Int32 adminUserRightID)
		{
		
            adminUserRight.DeleteByAdminUserRightID(adminUserRightID);

		}
		 
        public AdminUserRightModel GetByAdminUserRightID (System.Int32 adminUserRightID)
        {
        
			EAdminUserRight entity = adminUserRight.GetByAdminUserRightID(adminUserRightID);
			
            AdminUserRightModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public AdminUserRightModel ConvertEntityToModel(EAdminUserRight entity)
		{
			if (entity == null)
            {
                return null;
            }
			AdminUserRightModel model = new AdminUserRightModel();
                        model.AdminUserRightID = entity.AdminUserRightID;
                        model.UserID = entity.UserID;
                        model.RightID = entity.RightID;
                        return model;
		}
		
		public EAdminUserRight ConvertModelToEntity(AdminUserRightModel model)
		{
			if (model == null)
            {
                return null;
            }
			EAdminUserRight entity = new EAdminUserRight();
                        entity.AdminUserRightID = model.AdminUserRightID;
                        entity.UserID = model.UserID;
                        entity.RightID = model.RightID;
                        return entity;
		}
		
		#endregion

        public IList<AdminUserRightModel> GetByUserID(int userID)
        {
            IList<EAdminUserRight> entityList= adminUserRight.GetByUserID(userID);
            if (entityList == null)
                return null;
            IList<AdminUserRightModel> modelList = new List<AdminUserRightModel>();

            foreach (var item in entityList)
            {
                modelList.Add(ConvertEntityToModel(item));
            }

            return modelList;

        }

        public Dictionary<int, int> GetRightIDs(int userID)
        {

            IList<EAdminUserRight> entityList = adminUserRight.GetByUserID(userID);
            if (entityList == null)
                return null;
            Dictionary<int, int> dic = new Dictionary<int, int>();

            foreach (var item in entityList)
            {
                dic.Add(item.RightID, 1);
            }

            return dic;

        }

    }
}